// Copyright 2022 jeff.li. and/or its affiliates.

#include <gtest/gtest.h>
#include <fstream>
#include <iostream>
#include "tbir/runtime/utf8_util.h"

#include <tbir/runtime/container.h>
#include <tbir/runtime/container/file_ref.h>
#include <tbir/runtime/jsonlib/json.h>

namespace tbir::runtime {

    TEST(Json, loads) {
        Unicode s(U"[1,2,\"3\"]");
        RTValue v = json_loads(UTF8Encode(s));
        std::cout << v << std::endl;
    }

    TEST(Json, load) {
        Unicode fn(U"./json_load_data.json");
        std::ofstream of(fn.encode());
        of << "{\"1\": \"23\", \"4\": [5, 6]}";
        of.close();
        File fp(fn);
        RTValue v = json_load(fp);
        std::cout << v << std::endl;
    }

    TEST(Json, dumps) {
        Dict d{{1,                 2},
               {Unicode(U"hello"), 3},
               {3,                 Unicode(U"tbir4")}};
        Unicode s = json_dumps(RTView(d));
        std::cout << s << std::endl;
        s = json_dumps(RTView(d), 2);
        std::cout << s << std::endl;
        s = json_dumps(RTView(d), 2, false);
        std::cout << s << std::endl;
    }

}  // namespace tbir::runtime
